package org.example.util;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener;

import java.util.List;

public class ExcelUtil {

    /**
     * 导出Excel文件
     * @param data
     * @param filename
     */
    public static void writeExcel(List<UserVo> data, String filename){
        System.out.println("写入数据到文件:" + filename);
        EasyExcel.write(filename, UserVo.class).sheet(0).doWrite(data);
    }

    public static void readExcel(String filename){
        EasyExcel.read(filename, UserVo.class, new PageReadListener<UserVo>(dataList -> {
            for (UserVo user : dataList) {
                System.out.println("读取到一条数据: {}" +  user);
            }
        })).sheet().doRead();
    }

    public static void main(String[] args) {
        String filename = "E:\\三禾一\\凌云\\项目资料\\用户模板.xlsx";
        ExcelUtil.readExcel(filename);
    }
}
